package com.water.quality.testing.dao;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.sql.Timestamp;


@TableName("water_data")
public class WaterData {
    /**
     * id
     */
    private String id;

    /**
     * 观测点id
     */
    private Long observationPointId;

    /**
     * 观测点名字
     */
    private String observationPointName;

    /**
     *
     */
    private double clarity;

    /**
     * ph
     */
    @TableField("pH")
    private double pH;

    /**
     *
     */
    private double particleSize;

    /**
     *
     */
    private double conductivity;

    /**
     * 温度
     */
    private double temperature;

    /**
     * 细菌含量
     */
    private double bacteria;

    /**
     * 氟含量
     */
    private double fluoride;

    /**
     * 水质等级
     */
    private String qualityLevel;

    /**
     * 创建时间
     */
    private Timestamp createdAt;

    public WaterData() {}

    public WaterData(double clarity, double pH, double particleSize, double conductivity, double temperature,
                     double bacteria, double fluoride, Long observationPointId, String observationPointName) {
        this.clarity = clarity;
        this.pH = pH;
        this.particleSize = particleSize;
        this.conductivity = conductivity;
        this.temperature = temperature;
        this.bacteria = bacteria;
        this.fluoride = fluoride;
        this.observationPointId = observationPointId;
        this.observationPointName = observationPointName;
        this.createdAt = new Timestamp(System.currentTimeMillis());
        this.qualityLevel = determineQualityLevel();
    }

    /**
     * 界定水质等级
     */
    private String determineQualityLevel() {
        if (clarity >= 8 && pH >= 6.5 && pH <= 8.5 && particleSize <= 100 && conductivity <= 1200 &&
                temperature >= 15 && temperature <= 25 && bacteria <= 500 && fluoride <= 1.5) {
            return "优";
        } else if (clarity >= 5 && pH >= 6.0 && pH <= 9.0 && particleSize <= 150 && conductivity <= 1500 &&
                temperature >= 10 && temperature <= 30 && bacteria <= 800 && fluoride <= 2.0) {
            return "良";
        } else {
            return "差";
        }
    }

    public Long getObservationPointId() {
        return observationPointId;
    }

    public void setObservationPointId(Long observationPointId) {
        this.observationPointId = observationPointId;
    }

    public String getObservationPointName() {
        return observationPointName;
    }

    public void setObservationPointName(String observationPointName) {
        this.observationPointName = observationPointName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getClarity() {
        return clarity;
    }

    public void setClarity(double clarity) {
        this.clarity = clarity;
    }

    public double getpH() {
        return pH;
    }

    public void setpH(double pH) {
        this.pH = pH;
    }

    public double getParticleSize() {
        return particleSize;
    }

    public void setParticleSize(double particleSize) {
        this.particleSize = particleSize;
    }

    public double getConductivity() {
        return conductivity;
    }

    public void setConductivity(double conductivity) {
        this.conductivity = conductivity;
    }

    public double getTemperature() {
        return temperature;
    }

    public void setTemperature(double temperature) {
        this.temperature = temperature;
    }

    public double getBacteria() {
        return bacteria;
    }

    public void setBacteria(double bacteria) {
        this.bacteria = bacteria;
    }

    public double getFluoride() {
        return fluoride;
    }

    public void setFluoride(double fluoride) {
        this.fluoride = fluoride;
    }

    public String getQualityLevel() {
        return qualityLevel;
    }

    public void setQualityLevel(String qualityLevel) {
        this.qualityLevel = qualityLevel;
    }

    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }
}